﻿function add_address() {
    shade("input-address-div");
    $("#new-address").css("margin-top", $(document).scrollTop() + ($(window).height() - $("#new-address").height()) / 2);
    $("#new-address").css("margin-left", $(document).scrollLeft() + ($(window).width() - $("#new-address").width()) / 2);
}

function check_address_submit() {
    if ($("#txtReceiver").val() == "") {
        alert("请输入收货人姓名");
        return false;
    }
    if ($("#txtArea").val() == "") {
        alert("请输入省市区/县");
        return false;
    }
    if ($("#txtStreet").val() == "") {
        alert("请输入乡镇/街道");
        return false;
    }
    if ($("#txtPostCode").val() == "") {
        alert("请输入邮政编码");
        return false;
    }
    if ($("#txtTel").val() == "") {
        alert("请输入联系电话");
        return false;
    }
    return true;
}

function submit_order() {

    if (!$('input:radio[name=rdbAddress]:checked').val()) {
        alert("请选择收货地址！")
        return false;
    } else {
        $("#hndAddress").val($('input:radio[name=rdbAddress]:checked').val());
    }


    if (!$('input:radio[name=rdbPayment]:checked').val()) {
        alert("请选择付款方式！")
        return false;
    } else {
        $("#hndPayment").val($('input:radio[name=rdbPayment]:checked').val());
    }

    if (!$('input:radio[name=rdbSippingDate]:checked').val()) {
        alert("请选择送货时间！")
        return false;
    } else {
        $("#hndSippingDate").val($('input:radio[name=rdbSippingDate]:checked').val());
    }
    return true;
}

function init_order_radio() {
    if ($("#hndAddress").val() != '') {
        $('input:radio[name=rdbAddress]').each(function() {
            if ($(this).val() == $("#hndAddress").val()) {
                $(this).attr("checked", "true")
            }
        });
    }

    if ($("#hndPayment").val() != '') {
        $('input:radio[name=rdbPayment]').each(function() {
            if ($(this).val() == $("#hndPayment").val()) {
                $(this).attr("checked", "true")
            }
        });
    }

    if ($("#hndSippingDate").val() != '') {
        $('input:radio[name=rdbSippingDate]').each(function() {
            if ($(this).val() == $("#hndSippingDate").val()) {
                $(this).attr("checked", "true")
            }
        });
    }
}